<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<script type="text/javascript" src="<s:url value="/js/jquery/jquery.collapse.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/protocol/investigator.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/protocol/comiteEtica.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/protocol/site.js"/>"></script>
<script type="text/javascript" src="<s:url value="/js/protocol/siteStaff.js"/>"></script>
<br />
<h5>Sites Selection</h5>
<s:if test="!list.isEmpty()">

    <div id="table_content">
        <table>
            <thead>
            <tr>
                <th>Site Name</th>
                <th>Site #</th>
                <th>Selected?</th>
                <th>Score</th>
                <th>Edit</th>
            </tr>
            </thead>
            <tbody>
            <s:iterator value="list" var="x">
                <tr>
                    <th><s:property value="centro.institucion"/></th>
                    <th><s:property value="siteNumber"/></th>
                    <th><s:property value="selectedLAF"/></th>
                    <th><s:property value="siteScoreLAF"/></th>
                    <th>
                        <s:form method="POST">
                            <s:url value="/images/edit.png" id="imageEdit"/>
                            <s:url value="/images/eye.png" id="imageView"/>
                            <s:hidden value="%{id.centroid}" name="id.centroid"/>
                            <s:hidden value="%{id.protocoloCompromisopaisprotocoloid}" name="id.protocoloCompromisopaisprotocoloid"/>
                            <s:hidden value="%{id.protocoloCompromisopaiscompromisopaisid}" name="id.protocoloCompromisopaiscompromisopaisid"/>

                            <s:submit type="image" src="%{imageEdit}" cssStyle="width: 20px;height: 20px;" value="Edit"  ></s:submit>
                        </s:form>
                    </th>
                </tr>
            </s:iterator>

            <tbody>
        </table>
    </div>
</s:if>

<s:form theme="simple" style="width: 100%;">
<table id="pic_table" class="tableFilter">
    <tbody>
        <s:url var="searchSitesURL" action="getSiteByInstitutionName"  namespace="/"/>
        <s:url var="searchPIURL" action="getInvestigatorsByNameSurname"  namespace="/Directories/Team"/>
        <s:url var="searchSIURL" action="getInvestigatorsSIByNameSurname"  namespace="/Directories/Team"/>
        <s:url var="searchComitesEticaURL" action="getComiteEticaByName"  namespace="/Directories/EthicsCommittee"/>
        <s:url var="searchInvURL" action="getInvolucradosByNameSurname"  namespace="/Directories/Team"/>

        <%--Here I hide ID info for editing--%>
        <s:hidden id="centro_id" name="id.centroid" value="%{id.centroid}"/>
        <s:hidden name="id.protocoloCompromisopaisprotocoloid" value="%{id.protocoloCompromisopaisprotocoloid}"/>
        <s:hidden name="id.protocoloCompromisopaiscompromisopaisid" value="%{id.protocoloCompromisopaiscompromisopaisid}"/>

        <tr>
            <td><div class="div_padding"></div></td>
            <td></td>
        </tr>

        <tr>
            <td>
                <label>Site Name</label>
            </td>
            <td>
                <!--It Sends SITE's ID to Server-->
                <s:textfield theme="simple"
                             name="protocoloCentro.centro.id"
                             id="siteId" readonly="true" cssClass="load_hidden"/>

                <!--search field for SITES-->
                <s:textfield theme="simple" id="searchSite" value="%{protocoloCentro.centro.institucion}"/>
                <s:a href="#" onclick="searchSites(
                $('#searchSite').val(),
                '%{searchSitesURL}')"
                theme="simple" >
                    <img src="<s:url value="/images/search.png"/>" alt="search"></s:a>

                <label id="labelRequiredSite" style="color: red">*</label>

            </td>
        </tr>
        <tr>
            <td></td>
            <td>
        <!--listado de sites-->
        <div id="sites-show-hide" class="collapse" style="display: none;">
            <h3>More Information</h3>
            <div id="selected-site-Information" style="margin-bottom: 25px;">
            </div>
        </div>
        </td>
        </tr>

        <tr>
            <td>
                <label>Site #</label>
            </td>
            <td>
                <s:textfield name="protocoloCentro.siteNumber" value="%{protocoloCentro.siteNumber}" theme="simple" />
            </td>
        </tr>

        <s:if test="#session.display == 'ARGENTINA'">
            <tr>
                <td style="width:200px; word-wrap: break-word;" class="formTextarea">
                    FEFYM
                </td>
                <td>
                    <s:select name="fefymLAF"
                              headerKey="-1" headerValue="Choose an option"
                              listKey="id" listValue="name" list="decisions"
                              value="fefymLAF" theme="simple" />
                </td>
            </tr>
        </s:if>

        <tr>
            <td>
                <label>Time for delivering supplies</label>
            </td>
            <td>
                <s:textfield name="protocoloCentro.timeForDeliveringSupplies"
                             value="%{protocoloCentro.timeForDeliveringSupplies}" theme="simple" />
            </td>
        </tr>

        <tr>
            <td style="width:200px; word-wrap: break-word;" class="formTextarea">
                Place where to deliver envelopes (if it is different from the site address)
            </td>
            <td>
                <s:textarea name="protocoloCentro.placeToDeliverEnvelopes"
                            value="%{protocoloCentro.placeToDeliverEnvelopes}" theme="simple"/>
            </td>
        </tr>

        <tr>
            <td style="width:200px; word-wrap: break-word;" class="formTextarea">
                Address to receive drugs and/or materials (if it is different from the above)
            </td>
            <td>
                <s:textarea name="protocoloCentro.addressToReceiveDrugs"
                            value="%{protocoloCentro.addressToReceiveDrugs}" theme="simple" />
            </td>
        </tr>

        <tr>
            <td style="width:200px; word-wrap: break-word;" class="formTextarea">
                Does your institution require the IEC approval to provide the institution approval?
            </td>
            <td>
                <s:select name="institutionRequiresIECLAF"
                          headerKey="-1" headerValue="Choose an option"
                          listKey="id" listValue="name" list="decisions"
                          value="institutionRequiresIECLAF" theme="simple" />
            </td>
        </tr>

        <tr>
            <td style="width:200px; word-wrap: break-word;" class="formTextarea">
                Selected for protocol?
            </td>
            <td>
                <s:select name="selectedLAF"
                          headerKey="-1" headerValue="Choose an option"
                          listKey="id" listValue="name" list="decisions"
                          value="pepe" theme="simple" />
            </td>
        </tr>

        <tr>
            <td style="width:200px; word-wrap: break-word;" class="formTextarea">
                Justification
            </td>
            <td>
                <s:textarea name="protocoloCentro.justificacion" value="%{protocoloCentro.justificacion}"
                    theme="simple" />
            </td>
        </tr>

        <tr>
            <td>
                <label>How do you rate this site?</label>
            </td>
            <td>
                <s:select name="siteScoreC" headerKey="-1" headerValue="Choose a score"
                          listKey="id" listValue="name" list="scores"
                          value="protocoloCentro.siteScore.id" theme="simple"/>
            </td>
        </tr>

        <tr>
            <td><div class="div_padding"></div></td>
            <td></td>
        </tr>

        <tr>
            <td colspan="2">

                <!--listado de comites de etica-->
                <div id="ethicscommittees-show-hide" class="collapse" style="display: none;width: 100%;">
                    <h2>Ethics Committees Selection</h2>
                    <div id="selected-ethicscommittees-Information" style="margin-bottom: 25px;">
                        <table>
                            <s:include value="ethicsCommitteesSelection.jsp" />
                        </table>
                    </div>
                </div>
            </td>
        </tr>


        <tr>
            <td><div class="div_padding"></div></td>
            <td></td>
        </tr>

        <tr>
            <td colspan="2">

                <!--listado de cda-->
                <div id="cda-show-hide" class="collapse" style="display: none;width: 100%;">
                    <h2>Master Confidential Disclosure Agreement</h2>
                    <div id="selected-cda-Information" style="margin-bottom: 25px;">
                    </div>
                </div>
            </td>
        </tr>

        <tr>
            <td><div class="div_padding"></div></td>
            <td></td>
        </tr>

        <tr>
            <td style="text-align: right;">
                <s:submit value="Save" action="save" theme="simple" onclick="return validate()"/>
            </td>
            <td>
                <s:submit value="Clear" action="main"
                          onclick="$('#centro_id').val('');" theme="simple"/>
            </td>
        </tr>


    </tbody>
</table>
</s:form>



<script type="text/javascript">
    selectItemMenu("sitesSelection");

    //cargo los elementos con comportamiento collapse
    var ids = [["sites-show-hide",false],["ethicscommittees-show-hide",true], ["cda-show-hide",true]];
    loadCollapse(ids);
    $("#ethicscommittees-show-hide").show();

    function loadSite(){
        var id = $('#siteId').val();
        var institution = $('#searchSite').val();

        var site = Site(id,undefined,institution,undefined,undefined);
        closeWindows(site);
    }

    /*muestra collapses para la edicion*/
    function init(){
        if(!$.isEmptyObject($('#centro_id').val())){
            loadSite();
        }
    }

    window.onload=init;

</script>
